package com.zhu.day.util;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

@Slf4j
public class DateUtils {


    public static final String formatAll = "yyyy-MM-dd HH:mm:ss";
    public static final String formatHM = "HH:mm";

    /**
     * localdateTime 转 时间戳
     *
     * @param localDateTime
     * @return
     */
    public static long localDateTime2MillSec(LocalDateTime localDateTime) {
        Long milli = System.currentTimeMillis();
        try {
            milli = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return milli;
    }

    public static String local2String(LocalDateTime time,String format) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
        String localTime = df.format(time);
        return localTime;
    }

    public static void main(String[] args) {
//        LocalDateTime ldt = LocalDateTime.parse("2018-01-12T17:07:05");
//        System.out.println(local2String(ldt,formatHM));
        String s = DateUtils.local2String(LocalDateTime.now(), "MM.dd");
        System.out.println(s);
    }

}
